$(function () {
    //加载表格数据
    methods.getTableData();
});

var data = {
    //分页
    paging: {
        currentPage: 1,
        pageSize: 10,
        total: 11,
        tableData: []
    },
    //搜索
    search: {},
    //当前对象
    currentObj: {}
};

var methods = {
    getAdminNameList: function (names) {
        var arr = [];
        if (names) {
            arr = names.split(",");
        }
        return arr;
    },
    //删除部门
    deleteDept: function (row) {
        layer.confirm("您确定要删除【" + row.name + "】吗？", function (index) {
            layer.close(index);
            ajax.post("/system/dept/deleteDept", {
                id: row.id
            }, function (res) {
                if (res.code == 1) {
                    layer.msg(res.msg);
                    methods.getTableData();
                } else {
                    layer.alert(res.msg);
                }
            })
        })
    },
    //查看部门用户
    showDeptUser: function (row) {
        var url = "/system/dept/dept_user?id=" + row.id + "&name=" + row.name;
        dialog.iframeInfo("100%", "100%", url, function () {
            methods.getTableData();
        });
    },
    //显示部门描述
    showDeptDescription: function (row) {
        data.currentObj = row;
        var title = "【" + row.name + "】内容预览";
        dialog.info(title, "860px", "90%", "deptDescription");
    },
    //添加部门页面
    saveOrUpdateDept: function (row) {
        var url = "/system/dept/dept_add_update";
        if (!StringUtil.isEmpty(row.id)) {
            url = url + "?id=" + row.id;
        }
        dialog.iframeInfo("100%", "100%", url, function () {
            methods.getTableData();
        });
    },
    //获取表格数据
    getTableData: function () {
        ajax.post("/system/dept/getDeptPagingData", {
            currentPage: data.paging.currentPage,
            pageSize: data.paging.pageSize
        }, function (res) {
            data.paging.total = res.data.total;
            data.paging.tableData = res.data.rows;
        })
    },
    //处理页面大小变化
    handleSizeChange: function (val) {
        data.paging.pageSize = val;
        data.paging.currentPage = 1;
        methods.getTableData();
    },
    //处理当前页面变化
    handleCurrentChange: function (val) {
        data.paging.currentPage = val;
        methods.getTableData();
    },
    //处理对话框关闭
    handleDialogClose: function () {
        data.dialog.loading = false;
        data.dialog.disabled = false;
        data.dialog.title = "信息";
        data.currentObj = {};
    }

};
var vm = new Vue({data: data, methods: methods}).$mount("#app");
